var util = require("../../../utils/util.js"),
    {api} = require("../../../utils/api.js"),
    app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: null,
        integral: null,
        signWidth:'0'
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        wx.hideShareMenu();
    },
    onShow() {
        // this.getUserMessage();
        this.getUsers();
        // this.integralIndex();
    },
    async integralIndex(){
        const {data} = await api.IntegralIndex();
    },
    async getUsers() {
        const data = await app.getUsers();
        console.log('data',data)
        let signWidth='0%';
        if(data && data.integral && data.integral.days){
            signWidth=(data.integral.days/7)*100+'%'
        }
        data && this.setData({...data,...{signWidth}})
    },
    async signMethod() {
        if (util.getUserInfo(this.data.userInfo, true)) {
            await api.integralSign();
            wx.showToast({
                title: '签到成功',
                icon: 'success'
            })
            this.getUsers();
        }
    },
    gotoUser() {
        wx.navigateTo({
            url: '/pages/mine/userInfo/userInfo',
        })
    },
    bindMethod(){
        wx.navigateTo({
          url: '/pages/mine/thePatient/thePatient',
        })
    },
    gotoLogin() {
        wx.navigateTo({
            // url: '/pages/mine/thePatientAdd/thePatientAdd?is_me=1&type=1',
            url: '/pages/login/login',
        })
    },
    navMethod(e) {
        let {url,type} = e.currentTarget.dataset;
        if(type == 'tab'){
            return wx.switchTab({
                url
            })
        }
        if (util.getUserInfo(this.data.userInfo, true)) {
            wx.navigateTo({
                url
            })
        }
    },
    navMethods(e){
        let {url,type} = e.currentTarget.dataset;
        wx.navigateTo({
            url
        })
    },
    shopings(e){
        let {url,type} = e.currentTarget.dataset;
        wx.setStorageSync('goodsSwitch', 2)
        wx.switchTab({
            url
        })
    },
    onShareAppMessage(e) {
        return util.shareEvent(e)
      }

})